package com.aierjun.notepad;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


import shujuku.DBhelper;


/**
 * Created by Administrator on 2016/6/24.
 */
public class MMainActivity extends Activity {

    private DBhelper dBhelper;

    protected EditText btn_zhanghao, btn_mima;
    protected TextView error;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.denglu_activity);
        findView();
        getshuju();
    }

    public void findView() {
        btn_zhanghao = (EditText) findViewById(R.id.user_et);
        btn_mima = (EditText) findViewById(R.id.password_et);
        error = (TextView) findViewById(R.id.error_message);
    }
    public void getshuju(){
        dBhelper=new DBhelper(this,"Test.db",null,2);
        Button btn_go= (Button) findViewById(R.id.btn);
        btn_go.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SQLiteDatabase db=dBhelper.getWritableDatabase();
                String zhanghao=btn_zhanghao.getText().toString();
                String mima=btn_mima.getText().toString();
                Cursor cursor=db.query("test",null,null,null,null,null,null);
                if (cursor.moveToFirst()){
                    do {
                        String hao=cursor.getString(cursor.getColumnIndex("accounts"));
                        String mi=cursor.getString(cursor.getColumnIndex("password"));

                        Log.d("MMainActivity","test accounts is" +hao);
                        Log.d("MMainActivity","test accounts is" +mi);

                        if (zhanghao.equals(hao)&&mima.equals(mi)){
                            startActivity(new Intent(MMainActivity.this,HistoryActivity.class));
                        }
                        cursor.close();

                    }while (cursor.moveToNext());
                }

            }
        });
    }
}
